#-*- coding: utf8 -*-
from tutor.scripts import *
from tutor.plugins.sympy import *

# Entradas
with display_block('Variáveis'):
    n_iter = 0
    while True:
        n_iter += 1

        A = One * randint(1, 5) / randint(1, 5)
        Cx = One * randint(1, 5) / randint(1, 5)
        Cy = One * randint(1, 5) / randint(1, 5)
        m = Cy / Cx

        num, den = Cy.as_numer_denom()
        D = Cy + A
        num, den = (Cx + D).as_numer_denom()
        Zmax = (One * randint(0, 5) + num) / den
        if D.as_numer_denom()[0] > 20 or Zmax.as_numer_denom()[0] > 20:
            continue

        volume = -Half * Cx ** 2 * A * m - Half * Cx ** 2 * A - Half * A ** 2 * Cx + Zmax * A * Cx
        num, den = volume.as_numer_denom()
        if num > 30 or den > 10:
            continue

        correta = -(One / 3) * Cx ** 3 * A * m - (One / 3) * Cx ** 3 * A - (One / 4) * Cx ** 2 * A ** 2 + Half * Cx ** 2 * Zmax * A
        num, den = correta.as_numer_denom()
        if num > 30 or den > 10:
            continue

        volume_quadrado = -Half * Cx ** 2 * A - Half * Cx ** 3 * m - Half * A ** 2 * Cx - Cx ** 2 * A * m - Half * m ** 2 * Cx ** 3 + Zmax * A * Cx + Zmax * Cx ** 2 * m
        num, den = volume_quadrado.as_numer_denom()
        if num > 30 or den > 10:
            continue

        base_quadrada = -(One / 3) * Cx ** 3 * A - (One / 3) * Cx ** 4 * m - (One / 4) * Cx ** 2 * A ** 2 - Half * Cx ** 3 * A * m - (One / 4) * Cx ** 4 * m ** 2 + Half * Cx ** 2 * Zmax * A + Half * Cx ** 3 * Zmax * m
        num, den = base_quadrada.as_numer_denom()
        if num > 30 or den > 10:
            continue

        dis_1 = volume_quadrado
        ans = set([correta, volume, base_quadrada, dis_1])
        distratores = set()
        while len(distratores) < 4:
            n = oneof(*ans)
            number = n * randint(1, 5) / randint(1, 5)
            if number not in ans:
                distratores.add(number)
        dis_2, dis_3, dis_4, dis_5 = distratores

        break

